package com.eastfair.home.service.impl;

import com.eastfair.auth.api.UserAccountServiceFeign;
import com.eastfair.auth.dto.UserAccountDto;
import com.eastfair.auth.vo.UserAccountVo;
import com.eastfair.core.base.R;
import com.eastfair.home.service.HomeUserAccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 账户服务.
 *
 * @author dqq
 * @date 2022 /6/29
 */
@Service
@Slf4j
public class HomeUserAccountServiceImpl implements HomeUserAccountService {

    @Resource
    private UserAccountServiceFeign userAccountServiceFeign;

    @Override
    public Map<Long, String> listUserAccount(List<Long> ids) {
        if (ids == null || ids.isEmpty()) {
            return new HashMap<>(16);
        }
        UserAccountDto userAccountDto = new UserAccountDto();
        userAccountDto.setUserIds(ids);
        R<List<UserAccountVo>> userR = userAccountServiceFeign.querySimpleByIds(userAccountDto);
        if (!userR.getIsSuccess()) {
            return new HashMap<>(16);
        }
        List<UserAccountVo> userAccountVoList = userR.getData();
        if (userAccountVoList == null || userAccountVoList.isEmpty()) {
            return new HashMap<>(16);
        }
        Map<Long, String> userMap = new HashMap<>(16);
        for (UserAccountVo userAccountVo : userAccountVoList) {
            userMap.put(userAccountVo.getId(), userAccountVo.getRealName());
        }
        return userMap;
    }
}
